package thread;

public class ThreadReference {
    public static void main(String[] args) throws InterruptedException {
        Thread mainThread=Thread.currentThread();//获取主线程的引用
        Thread thread=new Thread(()-> {
            System.out.println("thread线程开始等待");
            try {
                mainThread.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);//让thread线程等待main线程
            }
            System.out.println("thread线程等待结束");
        });
        thread.start();
        Thread.sleep(2000);
        System.out.println("main线程结束");
    }
}
